/**
 * File: ArcMultiplicitySummary.java
 * Created by: mhaimel
 * Created on: Mar 25, 2010
 * CVS:  $Id: ArcMultiplicitySummary.java 1.0 Mar 25, 2010 12:02:07 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.model.graph.curtain.filter;

import java.util.List;

import uk.ac.ebi.curtain.model.graph.Arc;
import uk.ac.ebi.curtain.model.graph.curtain.CategoryReadInfo;
import uk.ac.ebi.curtain.model.graph.curtain.ContigInfo;
import uk.ac.ebi.curtain.model.graph.curtain.ReadWrapper;

/**
 * @author mhaimel
 *
 */
public class ArcMultiplicitySummary extends AbstractStatistic<Arc<ContigInfo, ReadWrapper>> {
	
	public ArcMultiplicitySummary(Integer categories) {
		super(categories);
	}
	
	@Override
	protected Integer getValue(Arc<ContigInfo, ReadWrapper> arc, int cat) {
		CategoryReadInfo info = arc.getValue().getInfo(cat);
		if(null != info){
			Integer mult = info.getMultiplicity();
			if(mult > 0){
				return mult;
			}
		}
		return null;
	}
	
	public String getCountPerMult(int cat){
		StringBuffer sb = new StringBuffer();
		List<Integer> list = getSortedArray(cat);
		int cnt = 0;
		Integer curr = 0;
		int size = list.size();
		for(int i = 0; i < size; ++i){
			Integer id = list.get(i);
			if(!id.equals(curr)){
				if(cnt > 0){
					sb.append(curr).append("\t").append(cnt).append("\n");
				}
				cnt = 0;
				curr = id;
			} 
			++cnt;
		}
		if(cnt > 0){
			sb.append(curr).append("\t").append(cnt).append("\n");
		}
		return sb.toString();
	}
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		int length = getCategories();
		boolean nl = false;
		for(int i = 0; i < length; ++i){
			if(nl) {
				sb.append("\n");
				nl = false;
			}
			sb.append(i).append("a) ").append(getStatistic(i)).append("\n");
			sb.append(i).append("b) ").append(getUniqueStatistic(i));
			nl = true;
		}
		return sb.toString();
	}
	



}
